package com.pingan.agentbank.aaos.testme;



import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.pingan.agentbank.aaos.pojo.ApproLineInfo;
import com.pingan.vframe.lang.EIterable;
import com.pingan.vframe.lang.Handler;
import com.pingan.vframe.logging.Log;
import com.pingan.vframe.logging.LogFactory;
import com.pingan.vframe.sdo.ServiceData;
import com.pingan.vframe.threadpool.ThreadPool;
import com.pingan.vframe.util.FileUtil;
import org.junit.Test;

import java.io.*;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;


public class Test2 {

    //private static final Log log = LogFactory.getLog();

    public static void main(String[] args) {
        int i = 0;
        System.out.println(i++);
        System.out.println(i++);
        /*if (true){
            throw new RuntimeException();
        }*/
        System.out.println(i++);
        System.out.println(i++);
        System.out.println(i++);

        ThreadPool threadPool = ThreadPool.getThreadPool("DB");
        ThreadPool threadPoolTask = ThreadPool.getThreadPool("Task");
        while (true){}

    }


    @Test
    public void method1(){
        File file = new File("D:\\Mine\\pass.txt");
        System.out.println(file.getName());
        System.out.println(file.getPath());
        System.out.println(file.getParent());
        System.out.println(file.getParentFile());
        System.out.println(file.exists());
        System.out.println(file.length());
        System.out.println(file.getTotalSpace());
        System.out.println(file.getUsableSpace());

    }



    @Test
    public void method6(){
        try {
            FileInputStream fileInputStream = new FileInputStream("D:/temp/3.txt");
            int i = 0;
            while((i = fileInputStream.read())!=-1){
                System.out.println(i);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println("----------------");
        try {
            FileReader fileReader = new FileReader("D:/temp/3.txt");
            int i = 0;
            while ((i=fileReader.read())!=-1){
                char a = (char) i;
                System.out.println(a);
            }
            System.out.println(fileReader.getEncoding());

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }



    @Test
    public void method8(){

        try {
            InputStream inputStream = new FileInputStream("D:/temp/3.txt");
            System.out.println(inputStream.available());
            int i = -1;
            int num = 0;
            while ((i=inputStream.read())!=-1){
                System.out.println(i);
                System.out.println((char)i);
                num++;
            }
            System.out.println(num);
            System.out.println(inputStream.available());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println("------------------");

        try {
            Reader reader = new FileReader("D:/temp/3.txt");

            int i = -1;
            int num = 0;
            while ((i=reader.read())!=-1){
                System.out.println(i);
                System.out.println((char) i);
                num++;
            }
            System.out.println(num);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }



    @Test
    public void method10(){
        File file = new File("D:\\temp\\temp");
        String[] strings = file.list();
        System.out.println(Arrays.toString(strings));
    }

    @Test
    public void method11(){
        //行分隔符 文件分隔符 路径分隔符
        //换行符
        String sb ="abc";
        sb = sb + "\n";
        sb = sb + "123";
        System.out.println(sb);
    }



    @Test
    public void method13(){
        Date date = new Date();
        System.out.println(date);
    }

    @Test
    public void method14(){
        StringBuffer sb = new StringBuffer();
        sb.append("a\rb");
        //sb.append("\t");
        //sb.append("\n");
        //sb.append("\r");
        sb.append("b");
        System.out.println(sb.toString());
    }

    @Test
    public void method15(){
        try {
            //byte[] bytes = "你好".getBytes("gbk");
            byte[] bytes = "你好".getBytes("utf8");

            System.out.println(Arrays.toString(bytes));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void method16(){

        try {
            InputStream inputStream = new FileInputStream("D:\\temp\\temp\\123.txt");
            InputStreamReader isr = new InputStreamReader(inputStream,"gbk");
            BufferedReader br = new BufferedReader(isr);
            int i = -1;
            while ((i = br.read())!=-1){
                char c = (char) i;
                System.out.println(c);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    @Test
    public void method17(){

        try {
            OutputStream outputStream = new FileOutputStream("D:\\temp\\temp1.txt");
            outputStream.write("你好".getBytes("gbk"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }



    @Test
    public void method19(){



        EIterable<String> eIterable = FileUtil.lineReader(new File("D:\\用户\\EX_WLJR_DURUNMIN\\Desktop\\temp\\123.txt"),"utf8");
        eIterable.each(new Handler<String>() {
            int i = 0;
            @Override
            public State handle(String s) {

                System.out.println(s+"--->"+i);
                i++;

                return CONTINUE;
            }
        });
    }



    @Test
    public void method21(){
        //FileUtil.fileCopy("D:\\用户\\EX_WLJR_DURUNMIN\\Desktop\\temp\\123.txt","D:\\用户\\EX_WLJR_DURUNMIN\\Desktop\\temp\\456.txt");

        byte[] bytes = new byte[1024];
        int read = 0;
        try {
            InputStream inputStream = new FileInputStream("D:\\用户\\EX_WLJR_DURUNMIN\\Desktop\\temp\\123.txt");
            OutputStream outputStream = new FileOutputStream("D:\\用户\\EX_WLJR_DURUNMIN\\Desktop\\temp\\1213.txt");
            while ((read = inputStream.read(bytes))!=-1){
                outputStream.write(bytes,0,read);
            }
            inputStream.close();
            outputStream.flush();
            outputStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    @Test
    public void method22(){
        System.out.println("你好");
        //log.info("我好");
    }

    @Test
    public void method23(){
        String line = "";

        try {
            InputStream inputStream = new FileInputStream("D:\\temp\\sourDir\\UCCB-APPROVAL-20181107-01.txt");
            byte[] bytes = new byte[inputStream.available()];
            inputStream.read(bytes);
            line = new String(bytes);
            ApproLineInfo approLineInfo = JSON.parseObject(line,new TypeReference<ApproLineInfo>(){});
            System.out.println(approLineInfo);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }




    }

    @Test
    public void method24(){

        try {
            System.out.println("1412".getBytes("gbk").length);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        StringBuffer sb = new StringBuffer();
        sb.append("1991");
        System.out.println(sb);
    }



    @Test
    public void method27(){
        System.out.println(Integer.valueOf("007"));

    }
    @Test
    public void method28(){
        int i = 10;
        assert (i==101);
    }

    @Test
    public void method30(){
        int i = 10;
        assert (i==101);
    }

    @Test
    public void method31(){
        StringBuffer stringBuffer = new StringBuffer(null);
    }

    @Test
    public void method32(){
        ServiceData serviceData = new ServiceData();
        String haha = serviceData.getString("haha");
        System.out.println(serviceData.getString("haha"));
        System.out.println(haha);
    }

    /*
    * 生成文件脚本
    * */
    @Test
    public void method33(){
        String string = "{\"application_no\":\"6a2292c4-790c-4a39-9094-140a7ea23aa8\",\"party_no\":\"9537\",\"expand_branch\":\"\",\"chinese_name\":\"李小明\",\"sex\":\"M\",\"birth_date\":\"19911125\",\"owner_name\":\"lixiaoming\",\"mobile\":\"15738885696\",\"email\":\"\",\"country_citizen\":\"\",\"global_type\":\"1\",\"global_id\":\"410823199111070000\",\"global_eff_enddate\":\"20271115\",\"global_eff_flag\":\"\",\"issuing_authority\":\"\",\"marital_status\":\"1\",\"children_flag\":\"1\",\"education\":\"02\",\"phone_area\":\"0371\",\"home_phome\":\"7683791\",\"address1\":\"城市经典玉树\",\"address2\":\"城市经典玉树\",\"address3\":\"城市经典玉树\",\"address4\":\"城市经典玉树\",\"postcode\":\"454950\",\"residential_type\":\"1\",\"companyname\":\"住建局\",\"departname\":\"审计科\",\"post\":\"科长\",\"employer_add1\":\"上海市黄浦路111号\",\"employer_add2\":\"上海市黄浦路111号\",\"employer_add3\":\"上海市黄浦路111号\",\"employer_add4\":\"上海市黄浦路111号\",\"employer_postcode\":\"454950\",\"employer_phone_areano\":\"0371\",\"employer_phone\":\"7758258\",\"company_type\":\"01\",\"working_years\":\"20\",\"annual_income\":\"1000\",\"ex_working_years\":\"2\",\"immidediate_name\":\"王大明\",\"immidediate_relation\":\"2\",\"immidediate_mobile\":\"15738518183\",\"other_name\":\"周杰伦\",\"other_relation\":\"2\",\"other_mobile\":\"13782850669\",\"car_number\":\"\",\"car_brand\":\"\",\"bank_account\":\"123\",\"mainBillingPostType\":\"电子账单\",\"send_addr_type\":\"1\",\"salses_name\":\"王岐山\",\"sales_code\":\"001\",\"sales_company_code\":\"\",\"application_tool\":\"\",\"applytime\":\"\",\"upload_cardtye\":\"\",\"creditcardCategory\":\"信用卡\",\"creditcardType\":\"白金卡\",\"collection_no\":\"11111\",\"bar_code\":\"123456\",\"swimmingGold\":\"0.50\",\"source_code\":\"\",\"affinityCode\":\"中国人民银行\",\"applicationFlag\":\"\",\"positionname\":\"\",\"referrer_globalid\":\"\",\"referrer_mobile\":\"\",\"channel_id\":\"\",\"expand_source\":\"\",\"monthly_mortgage_payment\":\"\",\"payment_limit_type\":\"\",\"campaign_code\":\"\",\"giveCardCity \":\"\",\"referrer_name\":\"\",\"expand_no\":\"\",\"agentunit\":\"UCCB\",\"reside_years\":\"50\",\"reside_add1\":\"张江以南\",\"reside_add2\":\"张江以南\",\"reside_add3\":\"张江以南\",\"reside_add4\":\"张江以南\",\"reside_postcode\":\"9999\",\"job_code\":\"023\",\"job_description\":\"032\",\"certification_type\":\"中国税收居民\",\"isOwnerMobile\":\"1\",\"ownerMobileStatus\":\"2\",\"useTimeScore\":\"2\",\"audit_result\":\"通过\",\"amount\":\"1000\",\"refuse_code\":\"\"}\n";
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i <100 ; i++) {
            sb.append(string);
        }
        //System.out.println(sb.toString());

        String fileName = "D:\\temp\\sourDir\\UCCB-APPROVAL-20181207-41";
        OutputStream outputStream = null;
        try {
            outputStream = new FileOutputStream(fileName+".txt");
            outputStream.write(sb.toString().getBytes());
            outputStream.flush();
            outputStream.close();

            File file = new File(fileName+".ok");
            file.createNewFile();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void method34(){
        System.out.println(System.currentTimeMillis());
    }


    /*
    * 全角半角
    * */
    @Test
    public void method35(){
        char c = 12288;
        System.out.println("1"+c+"2");
        System.out.println("1"+" "+"2");
    }

    @Test
    public void method36(){
        for (int i=65281;i<=65374;i++){
            System.out.println((char)i);
        }

    }

    @Test
    public void method37(){
        String string = "";
        char[] chars = string.toCharArray();
        System.out.println(chars.length);
    }




}
